/*
 * @lc app=leetcode.cn id=896 lang=typescript
 *
 * [896] 单调数列
 */

// @lc code=start
function isMonotonic(nums: number[]): boolean {
    if (nums.length === 1) return true;
    let tag = 0;
    let start = 0;

    while (tag === 0) {
        tag = nums[start] - nums[start + 1];
        start++;
    }

    for (let i = start + 1; i < nums.length; i++) {
        const element = nums[i];
        const prev = nums[i - 1];
        if ((prev - element) * tag < 0) {
            return false;
        }
    }
    return true;
}
// @lc code=end
